package leetCode.q35;

public class Solution {
    public int searchInsert(int[] nums, int target) {
        int len = nums.length;

        int i = 0;
        int j = len-1;
        int mid = (i+j)/2;
        while (j>=i){
            if(nums[mid] == target) {
                return mid;
            } else {
                if (nums[mid]>target){
                    j = mid-1;
                }else {
                    i = mid+1;
                }

                mid = (i+j)/2;
            }
        }

        //没找到
        return i;
    }

    public static void main(String[] args) {
        System.out.println(new Solution().searchInsert(new int[]{1,3,5,7}, 9));
    }
}
